Profiling enables examination of program behavior to focus performance tuning. A profiler is an automated tool that produces a profile of a program from information collected during program execution. A profile captures behavioral characteristics of a program. One or more portions of program can be identified from a profile as candidates for optimization. For example, a profile might indicate that an excessive amount of time is spent executing a particular function. In other words, a profile aids understating of program behavior to allow concentration of optimization efforts. Profilers are often classified based on their methods of gathering data, among other things.
There are two distinct types of approaches to gathering profile data, namely instrumentation and sampling. In the instrumentation approach, code is added to a program to collect information during execution. Here, the added code is an instrument that measures program behavior as the program executes. For example, the frequency and duration of function calls can be measured. In the sampling approach, an executing program is halted periodically, using operating system functionality, and sampled to determine the current state of execution. Accordingly, it can be noticed that twenty-percent of the time the program is executing a specific code point, for example. The sampling approach thus provides a statistical approximation rather than exact data.
Profile data is often presented as a call tree (a.k.a., call graph) that breaks down program execution. For example, a call tree can show function execution paths that were traversed in a program. The root node of the call tree can point to the entry point into the program and each other node in the tree can identify a called function as well as performance data such as execution time of the called function. The edges between nodes can represent function calls, and cycles can be indicative of recursive calls. The call tree can be analyzed by a developer to identify program hotspots, such as functions that occupy a large portion of execution time, among other things.